var fractionToDecimal = function(numerator, denominator) {
    let str = [];
    if(numerator == 0){
        return "0"
    }
    if((numerator ^ denominator) < 0) str.push("-")
    let num = Math.abs(numerator)
    let den = Math.abs(denominator)
    let map = new Map()

    //整数部分
    str.push(Math.floor(num / den))
    if(num % den == 0) {
        return str.join("")
    }
    str.push(".")

    //小数部分
    let remain = num % den
    if(remain && !map.has(remain)){
        map.set(remain,str.length)
        remain = remain * 10
        str.push(Math.floor(remain / den))
        remain = remain % den
    }
    if(map.has(remain)){
        str.push(")")
        let index = map.get(remain)
        str.splice(index,0,"(")
    }
    return str.join("")
};

console.log(fractionToDecimal(4,333))
